home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / program / 569 / rsctools / rsh.man < prev    next >
Text File  |  1992-06-01  |  17KB  |  362 lines

  1. RSH                        ST Programmer's Manual                       RSH
  2.  
  3.  
  4. NAME
  5.  
  6.       rsh - generates C source code from GEM resource files
  7.  
  8. SYNOPSIS
  9.  
  10.       rsh [-bflnqstvV] [-ac [skeleton-file]] infile [outfile]
  11.  
  12. DESCRIPTION
  13.  
  14.       Rsh is a utility designed to facilitate imbedding of resource files
  15.       within GEM applications.  The basic function of rsh is generation
  16.       of "RSH" output files based on resource file data, where an RSH
  17.       file is a C source file following the conventions defined by the
  18.       DRI/Atari resource construction program (RCS).  Rsh goes beyond RCS
  19.       in speed, convenience of use, compiler-dependent keyword support, and
  20.       automation of the imbedding process.  In particular, rsh can be used
  21.       in a makefile, and as long as an appropriate rule is defined for
  22.       making a .c file from a .rsc file, one can just include the .o filename
  23.       with the list of objects comprising the program, and make will call
  24.       rsh transparently (and if it's a good make, it will delete the
  25.       intermediate .c file, leaving just the .rsc and the compiled .o file).
  26.       To complete the automation process, rsh is capable of merging its
  27.       output with a "skeleton file," which contains the necessary replacements
  28.       for `rsrc_load' and other GEM functions; when this option is used,
  29.       rsh generates a stand-alone source file that includes everything
  30.       needed to imbed a resource within an application.
  31.  
  32.  
  33.       Generating RSH Files
  34.       --------------------
  35.  
  36.       In its simplest form, the syntax for the rsh command is:
  37.  
  38.          rsh resource-file
  39.  
  40.       An extension isn't required for the resource file; if none is present,
  41.       rsh appends ".RSC" to the filename (if the file in fact has no extension,
  42.       indicate this by ending the filename with a period).  The above command
  43.       creates a file with the same basename as the resource file but with
  44.       the extension "RSH"; the RSH file is created in the current directory.
  45.       If the file should be placed elsewhere or given a different basename,
  46.       the "outfile" must be specified.  For example,
  47.  
  48.          rsh c:\test f:\src\out
  49.  
  50.       results in out.rsh being placed in the f:\src directory.  Notice that
  51.       the RSH extension was appended in this case; if instead we specified the
  52.       outfile as "out.", no extension would be appended.  If we had specified
  53.       the outfile as "out.c", then this name would be used as is.
  54.  
  55.  
  56.       Compiler and Language Keyword Support
  57.       -------------------------------------
  58.  
  59.       Since it's always a good programming practice to hide as much detail
  60.       as possible, rsh supports the C `static' keyword through the `-s'
  61.       option.  When `-s' is used, `rs_object', `rs_tedinfo', etc. are all
  62.       made static (note that this doesn't make any sense unless using the
  63.       skeleton file merging feature, described later).
  64.  
  65.       The Lattice C 5 compiler supports the modifiers `__near' and `__far',
  66.       which control the section where data is placed.  In particular, a
  67.       Lattice C 5 program has 64 K of near (base-relative) data, which can
  68.       be accessed more efficiently than far (absolute) data.  Since resource
  69.       file data is almost always accessed via pointers, for which this
  70.       distinction is meaningless, it's desirable to make the resource data
  71.       far, so that it doesn't consume precious near data space.  Use the `-f'
  72.       option to make all resource data far and `-n' to make it near.  These
  73.       two options are mutually exclusive, and the default is to use neither.
  74.  
  75.       Note: although Lattice C 5 supports __far data, the semantics of this
  76.       modifier appear to be only partially implemented.  For example, the
  77.       following statement:
  78.  
  79.          char * __far rs_strings[] = {"a", "b",};
  80.  
  81.       makes the array `rs_strings' far, but _not_ the data.  This is expected.
  82.       However, ideally, one could use __far a second time to make the data
  83.       itself far, as in
  84.  
  85.          __far char * __far rs_strings...
  86.  
  87.       but this doesn't seem to work.  According to the compiler output, all
  88.       the string data ends up in the merged or near data section, while the
  89.       array is placed in the far data segment.  If one uses the `-cs' compiler
  90.       option, which merges identical string constants, the array data is moved
  91.       out of the near segment and into the code segment, which effectively
  92.       makes it far (however, it would be better if the data was placed in
  93.       the data segment, where it properly belongs).
  94.  
  95.  
  96.       Compatibility Considerations
  97.       ----------------------------
  98.  
  99.       Unfortunately, not all compilers agree on types used to define GEM data
  100.       structures, nor do all resource construction programs create identical
  101.       resource files.  Rsh provides the following options which can account for
  102.       for these inconsistencies:
  103.  
  104.          Kuma/Mark Williams editor - This resource construction program treats
  105.             TEDINFOs differently from all other editors known to the author.
  106.             The Kuma editor pads the `te_ptext' field with zeros, so that it
  107.             will be at least as long as the `te_pvalid' field.  This is
  108.             presumably meant to be a safeguard, so that one needn't replace
  109.             the `te_ptext' pointer at run-time with the address of an array
  110.             large enough to hold the edited text (a very common practice).
  111.             Since rsh has no way of knowing what program created the resource,
  112.             one must use the `-t' option to force the Kuma-style treatment of
  113.             TEDINFOs.  But as long as one isn't depending on this undocumented
  114.             feature of the editor, smaller programs can be obtained by not
  115.             using this option.
  116.  
  117.          Escaping characters - Of course, the backslash and double quote
  118.             must be escaped with a backslash to be used literally in a
  119.             quoted string.  Since the `rs_strings' array is initialized with
  120.             quoted strings, this can present a problem.  Use the `-b' option
  121.             to force escaping of backslashes and use the `-q' option to
  122.             force escaping of quotes.  Since escaping may be controlled
  123.             through these options, one needn't modify any resource files
  124.             in which characters are already escaped.
  125.  
  126.          The type of `ob_spec' - depending on one's views, `ob_spec' might
  127.             have the type "unsigned long" or "void *".  By default rsh assumes
  128.             "void *", in order to conform with the Lattice C 5 aes.h OBJECT
  129.             typedef.  Since compilers vary in their treatment of type
  130.             mismatches in initialized data, rsh explicitly casts `ob_spec',
  131.             as well as all other potential type conflicts.  Thus, the rsh
  132.             default is to cast `ob_spec' as in "(void *) 1L".  However, some
  133.             may feel that the "unsigned long" type is more appropriate, even
  134.             to the point of modifying the aes.h file.  Use the `-l' option to
  135.             suppress the (void *) casting.
  136.  
  137.  
  138.       Skeleton Files
  139.       --------------
  140.  
  141.       As alluded to earlier, generation of an RSH file still leaves the
  142.       application writer with quite a bit of work in order to imbed the
  143.       resource file.  He absolutely must provide replacements for `rsrc_load'
  144.       and other members of the rsrc family; one approach is to maintain a
  145.       rsrc.c file containing these functions, with a #include "some-rsh-file"
  146.       line.  The file would typically be copied to a project directory and
  147.       the #include made specific.  Rsh provides a better way through its
  148.       "skeleton file" feature.
  149.  
  150.       A skeleton file is a source file containing whatever preprocessor
  151.       statements and functions that are necessary to complete the imbedding
  152.       process.  When the `-c' option is given, rsh copies the skeleton file
  153.       to its outfile, merging its RSH output at the position of the "%%" token
  154.       within the skeleton file.  The double-percent token must be in the first
  155.       column of a line, and it may not be followed by any character (other
  156.       than a line-terminator), if it is to recognized.
  157.  
  158.       Rsh locates skeleton files based on how they are specified on the
  159.       command line.  If the filename is given by itself (with no path
  160.       information), rsh searches for it in the directories listed in the
  161.       "LIB" environment variable; the feature will not work unless LIB is
  162.       defined.  On the other hand, if you specify a more or less fully
  163.       qualified path for the skeleton file, rsh won't consult LIB; rather,
  164.       it will look for the file only in the place you indicated.  The
  165.       default skeleton file is "c_rsh.skl" located along the LIB path.
  166.  
  167.          Example 1: rsh -c test.rsc
  168.  
  169.             This command causes the c_rsh.skl skeleton file to be merged with
  170.             rsh's RSH output.  The outfile is implicitly named test.rsh.
  171.  
  172.          Example 2: rsh -cother.skl test.rsc test.c
  173.  
  174.             This command causes the other.skl skeleton file to be merged with
  175.             rsh's RSH output, and the resulting file is named test.c.  If a
  176.             filename is given as an argument to the `-c' option, it must
  177.             immediately follow it, as above, because `-c' optionally takes
  178.             an argument.  Other.skl must lie along the LIB path for this to
  179.             work.
  180.  
  181.          Example 3: rsh -c.\other.skl test.rsc test.c
  182.  
  183.             Similar to example 2, except rsh looks for other.skl only in the
  184.             current directory.
  185.  
  186.          Example 4: rsh -cd:\skel\other.skl test.rsc test.c
  187.  
  188.             Similar to example 3, except rsh looks for other.skl only in the
  189.             d:\skel directory.
  190.  
  191.  
  192.       Putting it all together - rsh, skeleton files, and make
  193.       -------------------------------------------------------
  194.  
  195.       For illustration purposes, let's consider the following makefile,
  196.       designed for the GNU make and Lattice C 5:
  197.  
  198.          %.c : %.rsc
  199.             rsh -fls -c $< $@
  200.  
  201.          OBJS=\
  202.          main.o\
  203.          test.o
  204.  
  205.          CFLAGS=-rr -v -w -cfuis -d1
  206.  
  207.          testrsc.prg: $(OBJS)
  208.             clink.ttp   FROM  e:\lc\lib\csr.o\
  209.                               $(OBJS)\
  210.                         TO    $@\
  211.                         LIB   lcgsr.lib\
  212.                               lcsr.lib\
  213.                         BATCH XADDSYM
  214.  
  215.       This makefile defines a program, `testrsc.prg', made from the objects
  216.       `main.o' and `test.o'.  While main.o has a corresponding .c file, test.o
  217.       does not.  Rather, test.o is made directly from test.rsc.  This is
  218.       possible due to the new rule:
  219.  
  220.          %.c : %.rsc
  221.             rsh -fls -c $< $@
  222.  
  223.       which says, "in order to turn a .rsc file into a .c file, run the
  224.       following rsh command."  Thus, when make considers test.o, it uses
  225.       its builtin rule for making .o files from .c files, and it then looks
  226.       for `test.c'.  Since it doesn't find test.c, it next determines if
  227.       it has a rule for making .c files.  Discovering it can make a .c file
  228.       from a .rsc file, and further finding a .rsc file with the same basename
  229.       as the object it is trying to make, it applies the rule and runs rsh.
  230.       So, the first step in making test.o is:
  231.  
  232.          rsh -fls -c test.rsc test.c
  233.  
  234.       which creates test.c based upon the resource file `test.rsc' and
  235.       the default skeleton file `c_rsh.skl' (located along the LIB path).
  236.       The data objects in test.c are made static and far, and the type of
  237.       `ob_spec' is taken to be "unsigned long".  After creating test.c,
  238.       make then applies the rule for making a .o file from a .c file and
  239.       runs this command:
  240.  
  241.          lc -rr -v -w -cfuis -d1 test.c
  242.  
  243.       which creates the desired target test.o.  Finally, after running the
  244.       command to link the final program, make deletes the temporary file
  245.       created during the make process, namely, test.c (although test.c is
  246.       no longer needed, you can of course use make's .PRECIOUS pseudo-target
  247.       to suppress the deletion).
  248.  
  249.  
  250.       The supplied c_rsh.skl file
  251.       ---------------------------
  252.  
  253.       You should find one skeleton file, c_rsh.skl, among the files making
  254.       up the RSC-Tools package.  This file is designed for Lattice C 5, but
  255.       it shouldn't be too difficult to modify it for other compilers.  This
  256.       file contains all the support code that is required to imbed a resource
  257.       file within a program; the replacement functions use exactly the same
  258.       syntax as the standard GEM functions, so one may easily compile with
  259.       or without use of rsh, in other words, switch between using a standard,
  260.       non-imbedded resource and an imbedded one.  Please see the skeleton
  261.       file for additional comments.  In particular, Lattice C 5 #defines
  262.       several AES functions, including some we're replacing, so you will need
  263.       to be aware of this!
  264.  
  265.  
  266. OPTIONS SUMMARY
  267.  
  268.       Rsh support flexible ordering of options, as well as option
  269.       concatenation.  For example, the following commands:
  270.  
  271.          rsh -b -f -l test.rsc test.rsh
  272.          rsh -bfl test.rsc test.rsh
  273.          rsh test.rsc -bf test.rsh -l
  274.  
  275.       are equivalent.  Rsh interprets any `-' character as introducing an
  276.       option.  If one happens to have a file beginning with `-', the "end
  277.       of the options" can be indicated with the special token "--" (two
  278.       dashes).  Everything following the double-dash is assumed to be a
  279.       non-option.  Finally, consider the `-c' option again.  It was earlier
  280.       said to optionally take an argument, the name of a skeleton file.
  281.       While an option requiring an argument may be separated from its
  282.       argument by whitespace, options that optionally take an argument
  283.       must be immediately followed by their arguments.  Thus, the following:
  284.  
  285.          rsh -c a.skl test.rsc test.c
  286.  
  287.       won't work, because rsh doesn't recognize `a.skl' as the argument
  288.       to `-c'.  Rather, it assumes a.skl is the resource file, and searches
  289.       for the default skeleton file in the LIB path(s).  The correct
  290.       usage is:
  291.  
  292.          rsh -ca.skl test.rsc test.c
  293.  
  294.       which loads the a.skl skeleton file, as desired.
  295.  
  296.       The rsh options are summarized below.
  297.  
  298.       -b                   Escape backslashes in quoted strings.
  299.  
  300.       -ac [skeleton file]  Incorporate RSH output into a skeleton file.
  301.                            The filename argument is optional, and if
  302.                            given, must immediately follow the option
  303.                            character.  (Note: the `-a' option currently
  304.                            duplicates the functionality of `-c'; at some
  305.                            later date it may support assembly output)
  306.  
  307.       -f                   Make data objects far.
  308.  
  309.       -l                   Use "unsigned long" as the type of `ob_spec'
  310.                            (the default is "void *").
  311.  
  312.       -n                   Make data objects near.
  313.  
  314.       -q                   Escape quotes within quoted strings.
  315.  
  316.       -s                   Make data objects static.
  317.  
  318.       -t                   Pad TEDINFO `te_ptext' fields with '\0' so they
  319.                            are at least as long as their corresponding
  320.                            `te_pvalid' fields (for compatibility with the
  321.                            Kuma/MWC editor).
  322.  
  323.       -v                   Verbose mode.
  324.  
  325.       -V                   Print version and copyright notice.
  326.  
  327. NOTES
  328.  
  329.       Like most programming tools, rsh assumes you know what you're doing.
  330.       In particular, you won't be warned before rsh overwrites a file.
  331.       When generating a C file from a resource file, be careful that the
  332.       C filename doesn't conflict with any other modules.  One strategy
  333.       to avoid name conflicts is to have specific directories for each
  334.       project, and if, for example, the program is to be named test.prg, do
  335.       not name any module test.c (the module containing the `main' function
  336.       should be called "main.c").  Then one can name the resource file
  337.       "test.rsc" and use rsh in a makefile as described above; rsh will
  338.       create test.c as needed, make will delete it after it's compiled
  339.       successfully, and as long as these conventions are followed, there
  340.       will be no danger of inadvertently overwriting any files.
  341.  
  342. AUTHOR
  343.  
  344.       Doug Harrison
  345.  
  346.       Electronic mail:
  347.  
  348.          GEnie: D.S.HARRISON
  349.          Bix: dharrison
  350.          Compuserve: 72277,2315
  351.  
  352.       U.S. Mail:
  353.  
  354.          Doug Harrison
  355.          P.O. Box 66236
  356.          Baton Rouge, LA 70806-6236
  357.  
  358.       Please send any comments and criticisms to any of the above
  359.       addresses.  Shareware donations cheerfully accepted! (see the
  360.       accompanying README.TXT file for details on this and distribution
  361.       instructions)
  362.